package com.ruoyi.APPMS.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.APPMS.domain.Aftersale;
import com.ruoyi.APPMS.service.IAftersaleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 售后管理Controller
 *
 * @author monster
 * @date 2023-07-03
 */
@Api("售后管理类")
@RestController
@RequestMapping("/aftersale/aftersale")
public class AftersaleController extends BaseController
{
    @Autowired
    private IAftersaleService aftersaleService;

    /**
     * 查询售后管理列表
     */
    @ApiOperation("售后管理查询列表")
    @PreAuthorize("@ss.hasPermi('aftersale:aftersale:list')")
    @GetMapping("/list")
    public TableDataInfo list(Aftersale aftersale)
    {
        startPage();
        QueryWrapper<Aftersale> queryWrapper = new QueryWrapper<>();
        if(aftersale.getCustormerid()!=null&&!"".equals(aftersale.getCustormerid())){
            queryWrapper.eq("custormerid",aftersale.getCustormerid());
        }
        if(aftersale.getSalespersonid()!=null&&!"".equals(aftersale.getSalespersonid())){
            queryWrapper.eq("salespersonid",aftersale.getSalespersonid());
        }
        if(aftersale.getDescription()!=null&&!"".equals(aftersale.getDescription())){
            queryWrapper.like("description",aftersale.getDescription());
        }
        if(aftersale.getResult()!=null&&!"".equals(aftersale.getResult())){
            queryWrapper.like("result",aftersale.getResult());
        }
        List<Aftersale> list = aftersaleService.list(queryWrapper);
        return getDataTable(list);
    }

    /**
     * 导出售后管理列表
     */
    @ApiOperation("售后管理excel导出")
    @PreAuthorize("@ss.hasPermi('aftersale:aftersale:export')")
    @Log(title = "售后管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Aftersale aftersale)
    {
        QueryWrapper<Aftersale> queryWrapper = new QueryWrapper<>();
        if(aftersale.getCustormerid()!=null&&!"".equals(aftersale.getCustormerid())){
            queryWrapper.eq("custormerid",aftersale.getCustormerid());
        }
        if(aftersale.getSalespersonid()!=null&&!"".equals(aftersale.getSalespersonid())){
            queryWrapper.eq("salespersonid",aftersale.getSalespersonid());
        }
        if(aftersale.getDescription()!=null&&!"".equals(aftersale.getDescription())){
            queryWrapper.like("description",aftersale.getDescription());
        }
        if(aftersale.getResult()!=null&&!"".equals(aftersale.getResult())){
            queryWrapper.like("result",aftersale.getResult());
        }
        List<Aftersale> list = aftersaleService.list(queryWrapper);
        ExcelUtil<Aftersale> util = new ExcelUtil<Aftersale>(Aftersale.class);
        util.exportExcel(response, list, "售后管理数据");
    }

    /**
     * 获取售后管理详细信息
     */
    @ApiOperation("获取售后管理数据")
    @PreAuthorize("@ss.hasPermi('aftersale:aftersale:query')")
    @GetMapping(value = "/{aftersaleid}")
    public AjaxResult getInfo(@PathVariable("aftersaleid") Long aftersaleid)
    {
        return success(aftersaleService.getById(aftersaleid));
    }

    /**
     * 新增售后管理
     */
    @ApiOperation("售后管理增加")
    @PreAuthorize("@ss.hasPermi('aftersale:aftersale:add')")
    @Log(title = "售后管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Aftersale aftersale)
    {
        return toAjax(aftersaleService.save(aftersale));
    }

    /**
     * 修改售后管理
     */
    @ApiOperation("售后管理编辑更新")
    @PreAuthorize("@ss.hasPermi('aftersale:aftersale:edit')")
    @Log(title = "售后管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Aftersale aftersale)
    {
        return toAjax(aftersaleService.updateById(aftersale));
    }

    /**
     * 删除售后管理
     */
    @ApiOperation("售后管理批量删除")
    @PreAuthorize("@ss.hasPermi('aftersale:aftersale:remove')")
    @Log(title = "售后管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{aftersaleids}")
    public AjaxResult remove(@PathVariable List<Long> aftersaleids)
    {
        return toAjax(aftersaleService.removeByIds(aftersaleids));
    }
}
